namespace CLELCore.Assembly.CLELInstructions
{
	public class Ldstr : CLELInstruction
	{
		private Token _token;
		public Token Token
		{
			get
			{
				return _token;
			}
			set
			{
				_token = value;
			}
		}
		public override int Length
		{
			get
			{
				return 5;
			}
		}
		public Ldstr(int token) : base(CLELOpcode.LDSTR)
		{
			_token = new Token(token);
		}
		public Ldstr(Token token) : base(CLELOpcode.LDSTR)
		{
			_token = token;
		}

		public override byte[] GetBytes(bool little_endian)
		{
			byte[] ret = new byte[5];
			ret[0] = CLELOpcode.LDSTR;
			int i,j;
			int t = _token.GetEncodedToken();
			if(little_endian)
				j = 0;
			else
				j = 3;
			for(i = 1;i < 5;i++)
			{
				ret[i] = Bits.ByteFromInt(j,t);
				if(little_endian)
					j++;
				else
					j--;
			}
			return ret;
		}
		
		public override string ToString()
		{
			return "ldstr " + _token.ToString();
		}
	}
}
